<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>表单</title>
    <link rel="stylesheet" href="/frame/layui/css/layui.css">
    <link rel="stylesheet" href="/frame/static/css/style.css">
    <link rel="icon" href="/frame/static/image/code.png">
</head>
<body class="body">
<style>
</style>

<blockquote class="layui-elem-quote layui-text">
    这里放公告
</blockquote>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend id="save-title">添加角色</legend>
</fieldset>

<form class="layui-form" id="role-form">
    <input type="hidden" name="account_role_id"/>
    <div class="layui-form-item">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-block" style="padding-right: 30px;">
            <input type="text" name="account_role_name"  lay-verify="required" autocomplete="off" placeholder="请输入供角色名称" class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block" style="padding-right: 30px;">
            <textarea class="layui-textarea"  name="account_role_desc" placeholder="备注"></textarea>
        </div>
    </div
    <div class="layui-form-item">
        <div class="layui-input-block" style="margin-top: 70px;" >
            <button class="layui-btn" style="text-align: center;margin-left: 50px;" lay-submit lay-filter="demo1">保存</button>
            <button class="layui-btn layui-btn-primary" id="back-btn"  style="text-align: center;margin-left: 50px;">返回</button>
        </div>
    </div>

</form>

<script src="/frame/layui/layui.js" charset="utf-8"></script>
<script>
    var data = parent.rowJSONDate;
    layui.use(['form','layer'], function(){
        var form = layui.form
                ,$ = layui.jquery
                ,layer = layui.layer;

        if(data!=null){
            $("#save-title").text("编辑角色");
            $("input[name='account_role_id']").val(data.account_role_id);
            $("input[name='account_role_name']").val(data.account_role_name);
            $("textarea[name='account_role_desc']").val(data.account_role_desc);
        }


        //监听提交
        form.on('submit(demo1)', function(result){
            $.post("/role/save",
                    result.field,
                    function (result) {
                        if(Number(result.result)>0){
                            if(data!=null){
                                layer.msg("修改成功");
                                parent.layer.closeAll();
                                parent.tableIns.reload();
                            }else{
                                layer.confirm("添加成功！需要继续添加吗？",function(index){
                                    $('#role-form')[0].reset();
                                    layer.close(index);
                                    parent.tableIns.reload();
                                },function(index){
                                    layer.close(index);
                                    parent.layer.closeAll();
                                    parent.tableIns.reload();
                                })
                            }
                        }
                    },"json"
            );
            return false;
        });

        $('#back-btn').on('click',function(){
            parent.layer.closeAll('iframe')
        });

    });
</script>
</body>
</html>